package com.wzk.dwetl

import com.wzk.dwetl.utils.RrbitmapOrAggregationFunction
import com.wzk.dwetl.utils.RrUtils.{getCard, toBitmap}
import org.apache.spark.sql.SparkSession

object CubeDistinctAggrgationRead {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName(this.getClass.getSimpleName)
      .enableHiveSupport()
      .master("local")
      .getOrCreate()
    import spark.implicits._
    import org.apache.spark.sql.functions._

    spark.udf.register("getCard",getCard _)
    spark.sql(
      """
        |
        |select
        | province,
        | city,
        | region,
        | getCard(bitmap) as uv
        |from
        | test.bitmap_demo
        |""".stripMargin).show()
//    spark.close()

    spark.udf.register("aggr",RrbitmapOrAggregationFunction)
    spark.sql(
      """
        |select
        | province,
        | city,
        | getCard(aggr(bitmap)) as uv
        |from
        | test.bitmap_demo
        |group by
        | province,
        | city
        |with cube
        |
        |
        |""".stripMargin).show()
  }
}
